#![allow(dead_code, mutable_transmutes, non_camel_case_types, non_snake_case, non_upper_case_globals, unused_assignments, unused_mut)]
#![feature(extern_types)]
extern crate libc;
use primary::alloc_testing::*;
use primary::binomial_heap::*;
use primary::compare_pointer::*;
use primary::compare_string::*;
use primary::compare_int::*;
use primary::hash_pointer::*;
use primary::hash_string::*;
use primary::hash_int::*;
extern "C" {
    pub type _BinomialHeap;
    fn __assert_fail(
        __assertion: *const libc::c_char,
        __file: *const libc::c_char,
        __line: libc::c_uint,
        __function: *const libc::c_char,
    ) -> !;
                            }
pub const BINOMIAL_HEAP_TYPE_MAX: BinomialHeapType = 1;
pub const BINOMIAL_HEAP_TYPE_MIN: BinomialHeapType = 0;
#[no_mangle]
pub static mut test_array: [libc::c_int; 10000] = [0; 10000];
#[no_mangle]
pub extern "C" fn test_binomial_heap_new_free() {
    let mut heap: *mut BinomialHeap = std::ptr::null_mut();
    let mut i: libc::c_int = 0;

    while i < 10000 {
        heap = binomial_heap_new(
            BINOMIAL_HEAP_TYPE_MIN,
            Some(int_compare),
        );
        binomial_heap_free(heap);
        i += 1;
    }
}
#[no_mangle]
pub extern "C" fn test_binomial_heap_insert() {
    let mut heap: *mut BinomialHeap = std::ptr::null_mut();
    let mut i: libc::c_int = 0;

    heap = binomial_heap_new(
        BINOMIAL_HEAP_TYPE_MIN,
        Some(int_compare),
    );

    i = 0;
    while i < 10000 {
        unsafe {
            test_array[i as usize] = i;
        }
        assert_ne!(
            binomial_heap_insert(
                heap,
                unsafe { &mut *test_array.as_mut_ptr().offset(i as isize) as *mut libc::c_int as BinomialHeapValue },
            ),
            0,
            "binomial_heap_insert(heap, &test_array[i]) != 0"
        );

        i += 1;
    }

    assert_eq!(
        binomial_heap_num_entries(heap),
        10000 as libc::c_uint,
        "binomial_heap_num_entries(heap) == NUM_TEST_VALUES"
    );
    binomial_heap_free(heap);
}
#[no_mangle]
pub extern "C" fn test_min_heap() {
    let mut heap: *mut BinomialHeap = std::ptr::null_mut();
    let mut val: *mut libc::c_int = std::ptr::null_mut();
    let mut i: libc::c_int = 0;

    heap = binomial_heap_new(
        BINOMIAL_HEAP_TYPE_MIN,
        Some(int_compare),
    );

    i = 0;
    while i < 10000 {
        unsafe {
            test_array[i as usize] = i;
            assert_ne!(
                binomial_heap_insert(
                    heap,
                    &mut *test_array.as_mut_ptr().offset(i as isize) as *mut libc::c_int
                        as BinomialHeapValue,
                ),
                0,
                "binomial_heap_insert(heap, &test_array[i]) != 0"
            );
        }
        i += 1;
    }

    i = -1;
    while unsafe { binomial_heap_num_entries(heap) } > 0 {
        unsafe {
            val = binomial_heap_pop(heap) as *mut libc::c_int;
            assert_eq!(
                *val,
                i + 1,
                "*val == i + 1"
            );
            i = *val;
        }
    }

    unsafe {
        val = binomial_heap_pop(heap) as *mut libc::c_int;
        assert!(
            val.is_null(),
            "val == NULL"
        );
        binomial_heap_free(heap);
    }
}
#[no_mangle]
pub extern "C" fn test_max_heap() {
    let mut heap: *mut BinomialHeap = std::ptr::null_mut();
    let mut val: *mut libc::c_int = std::ptr::null_mut();
    let mut i: libc::c_int = 0;

    heap = binomial_heap_new(
        BINOMIAL_HEAP_TYPE_MAX,
        Some(int_compare),
    );

    i = 0;
    while i < 10000 {
        unsafe {
            test_array[i as usize] = i;
            assert_ne!(
                binomial_heap_insert(
                    heap,
                    &mut *test_array.as_mut_ptr().offset(i as isize) as *mut libc::c_int
                        as BinomialHeapValue,
                ),
                0,
                "binomial_heap_insert(heap, &test_array[i]) != 0"
            );
        }
        i += 1;
    }

    i = 10000;
    while binomial_heap_num_entries(heap) > 0 {
        unsafe {
            val = binomial_heap_pop(heap) as *mut libc::c_int;
            assert_eq!(
                *val,
                i - 1,
                "*val == i - 1"
            );
            i = *val;
        }
    }

    unsafe {
        val = binomial_heap_pop(heap) as *mut libc::c_int;
        assert!(
            val.is_null(),
            "val == NULL"
        );
        binomial_heap_free(heap);
    }
}
unsafe extern "C" fn test_insert_out_of_memory() {}
#[no_mangle]
pub unsafe extern "C" fn test_pop_out_of_memory() {}
